Added timestamp querying function, some code simplifications