Rearrange some code, add logger, add time