diff --git a/scripts/zmdc.pl.in b/scripts/zmdc.pl.in
index e26247894..e23413ca5 100644
--- a/scripts/zmdc.pl.in
+++ b/scripts/zmdc.pl.in
@@ -257,6 +257,8 @@ sub run {
   }
 
   my $fd = 0;
+
+  # THis also closes dbh and CLIENT and SERVER
   while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) {
     POSIX::close($fd++);
   }
@@ -300,16 +302,17 @@ sub run {
     
     if ( $Config{ZM_SERVER_ID} ) {
       if ( ! ( $secs_count % 60 ) ) {
-        Debug("Connecting");
         while ( (!$zm_terminate) and !($dbh and $dbh->ping()) ) {
           Warning("Not connected to db ($dbh)".($dbh?' ping('.$dbh->ping().')':''). ($DBI::errstr?" errstr($DBI::errstr)":'').' Reconnecting');
           $dbh = zmDbConnect();
         }
+        last if $zm_terminate;
+
         my @cpuload = CpuLoad();
         Debug("Updating Server record @cpuload");
         if ( ! defined $dbh->do(q{UPDATE Servers SET Status=?,CpuLoad=?,TotalMem=?,FreeMem=?,TotalSwap=?,FreeSwap=? WHERE Id=?}, undef,
             'Running', $cpuload[0], &totalmem, &freemem, &totalswap, &freeswap, $Config{ZM_SERVER_ID} ) ) {
-          Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID}".$dbh->errstr());
+          Error("Failed Updating status of Server record for Id=$Config{ZM_SERVER_ID} :".$dbh->errstr());
         }
       }
       $secs_count += 1;
@@ -375,7 +378,7 @@ sub run {
   } # end while
 
   dPrint(ZoneMinder::Logger::INFO, 'Server exiting at '
-      .strftime( '%y/%m/%d %H:%M:%S', localtime() )
+      .strftime('%y/%m/%d %H:%M:%S', localtime())
       ."\n"
       );
   if ( $Config{ZM_SERVER_ID} ) {
@@ -709,7 +712,7 @@ sub reaper {
           $process->{delay} = $Config{ZM_MAX_RESTART_DELAY};
         }
       }
-      Debug("Delay for $$process{command} is now $$process{delay}");
+      #Debug("Delay for $$process{command} is now $$process{delay}");
     } else {
       delete $cmd_hash{$$process{command}};
     }
diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp
index b91e88505..e42a82f2b 100644
--- a/src/zm_logger.cpp
+++ b/src/zm_logger.cpp
@@ -38,7 +38,7 @@
 #endif
 
 bool Logger::smInitialised = false;
-Logger *Logger::smInstance = 0;
+Logger *Logger::smInstance = NULL;
 
 Logger::StringMap Logger::smCodes;
 Logger::IntMap Logger::smSyslogPriorities;
@@ -58,9 +58,9 @@ static void subtractTime( struct timeval * const tp1, struct timeval * const tp2
 void Logger::usrHandler( int sig ) {
   Logger *logger = fetch();
   if ( sig == SIGUSR1 )
-    logger->level( logger->level()+1 );
+    logger->level(logger->level()+1);
   else if ( sig == SIGUSR2 )
-    logger->level( logger->level()-1 );
+    logger->level(logger->level()-1);
   Info("Logger - Level changed to %d", logger->level());
 }
 
@@ -79,7 +79,7 @@ Logger::Logger() :
   mFlush(false) {
 
   if ( smInstance ) {
-    Panic( "Attempt to create second instance of Logger class" );
+    Panic("Attempt to create second instance of Logger class");
   }
 
   if ( !smInitialised ) {
@@ -133,11 +133,11 @@ void Logger::initialise(const std::string &id, const Options &options) {
 
   std::string tempLogFile;
 
-  if ( (envPtr = getTargettedEnv("LOG_FILE")) )
+  if ( (envPtr = getTargettedEnv("LOG_FILE")) ) {
     tempLogFile = envPtr;
-  else if ( options.mLogFile.size() )
+  } else if ( options.mLogFile.size() ) {
     tempLogFile = options.mLogFile;
-  else {
+  } else {
     if ( options.mLogPath.size() ) {
       mLogPath = options.mLogPath;
     }
@@ -169,7 +169,7 @@ void Logger::initialise(const std::string &id, const Options &options) {
     tempSyslogLevel = config.log_level_syslog >= DEBUG1 ? DEBUG9 : config.log_level_syslog;
 
   // Legacy
-  if ( (envPtr = getenv( "LOG_PRINT" )) )
+  if ( (envPtr = getenv("LOG_PRINT")) )
     tempTerminalLevel = atoi(envPtr) ? DEBUG9 : NOLOG;
 
   if ( (envPtr = getTargettedEnv("LOG_LEVEL")) )
@@ -218,7 +218,7 @@ void Logger::initialise(const std::string &id, const Options &options) {
 
   mFlush = false;
   if ( (envPtr = getenv("LOG_FLUSH")) ) {
-    mFlush = atoi( envPtr );
+    mFlush = atoi(envPtr);
   } else if ( config.log_debug ) {
     mFlush = true;
   }
@@ -577,12 +577,12 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co
   }
 }
 
-void logInit( const char *name, const Logger::Options &options ) {
+void logInit(const char *name, const Logger::Options &options) {
   if ( !Logger::smInstance )
     Logger::smInstance = new Logger();
   Logger::Options tempOptions = options;
   tempOptions.mLogPath = staticConfig.PATH_LOGS;
-  Logger::smInstance->initialise( name, tempOptions );
+  Logger::smInstance->initialise(name, tempOptions);
 }
 
 void logTerm() {
diff --git a/src/zm_monitorstream.cpp b/src/zm_monitorstream.cpp
index d3721bf8f..56396e256 100644
--- a/src/zm_monitorstream.cpp
+++ b/src/zm_monitorstream.cpp
@@ -633,7 +633,7 @@ Debug(2, "Have checking command Queue for connkey: %d", connkey );
           // Send the next frame
           Monitor::Snapshot *snap = &monitor->image_buffer[index];
 
-            //Debug(2, "sending Frame.");
+          Debug(2, "sending Frame.");
           if ( !sendFrame(snap->image, snap->timestamp) ) {
             Debug(2, "sendFrame failed, quiting.");
             zm_terminate = true;
@@ -687,7 +687,7 @@ Debug(2, "Have checking command Queue for connkey: %d", connkey );
       } // end if buffered playback
       frame_count++;
     } else {
-      Debug(5,"Waiting for capture");
+      Debug(4,"Waiting for capture last_write_index=%u", monitor->shared_data->last_write_index);
     } // end if ( (unsigned int)last_read_index != monitor->shared_data->last_write_index ) 
 
     unsigned long sleep_time = (unsigned long)((1000000 * ZM_RATE_BASE)/((base_fps?base_fps:1)*abs(replay_rate*2)));
diff --git a/src/zm_video.cpp b/src/zm_video.cpp
index 22379f2b3..07bedc683 100644
--- a/src/zm_video.cpp
+++ b/src/zm_video.cpp
@@ -376,7 +376,10 @@ int X264MP4Writer::x264config() {
   x264params.b_annexb = 0;
 
   /* TODO: Setup error handler */
-  // x264params.i_log_level = X264_LOG_DEBUG;
+  if ( logDebugging() )
+    x264params.i_log_level = X264_LOG_DEBUG;
+  else
+    x264params.i_log_level = X264_LOG_NONE;
 
   /* Process user parameters (excluding preset, tune and profile) */
   for ( unsigned int i = 0; i < user_params.size(); i++ ) {
diff --git a/src/zma.cpp b/src/zma.cpp
index 83035f011..33dedbe54 100644
--- a/src/zma.cpp
+++ b/src/zma.cpp
@@ -83,7 +83,7 @@ int main( int argc, char *argv[] ) {
   while (1) {
     int option_index = 0;
 
-    int c = getopt_long (argc, argv, "m:h:v", long_options, &option_index);
+    int c = getopt_long(argc, argv, "m:h:v", long_options, &option_index);
     if ( c == -1 ) {
       break;
     }
@@ -144,7 +144,7 @@ int main( int argc, char *argv[] ) {
     unsigned int analysis_update_delay = monitor->GetAnalysisUpdateDelay();
     time_t last_analysis_update_time, cur_time;
     monitor->UpdateAdaptiveSkip();
-    last_analysis_update_time = time( 0 );
+    last_analysis_update_time = time(0);
 
     while( (!zm_terminate) && monitor->ShmValid() ) {
       // Process the next image
@@ -181,5 +181,5 @@ int main( int argc, char *argv[] ) {
   Image::Deinitialise();
   logTerm();
   zmDbClose();
-  return( 0 );
+  return 0;
 }
diff --git a/web/api/app/Plugin/CakePHP-Enum-Behavior b/web/api/app/Plugin/CakePHP-Enum-Behavior
index ea90c0cd7..ca91b87fd 160000
--- a/web/api/app/Plugin/CakePHP-Enum-Behavior
+++ b/web/api/app/Plugin/CakePHP-Enum-Behavior
@@ -1 +1 @@
-Subproject commit ea90c0cd7f6e24333a90885e563b5d30b793db29
+Subproject commit ca91b87fda8e006e4fca2ed870f24f9a29c2905d
diff --git a/web/api/app/Plugin/Crud b/web/api/app/Plugin/Crud
index 0bd63fb46..c3976f147 160000
--- a/web/api/app/Plugin/Crud
+++ b/web/api/app/Plugin/Crud
@@ -1 +1 @@
-Subproject commit 0bd63fb464957080ead342db58ca9e01532cf1ef
+Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5