Adding timestamping and simplifying code