Cleaned up the code a bit
Updated code to check for uninitialized timestamps