refactor and add timestamps