Cleaned up logic for generating the time string and added some docblocks.