Fix timestamp loop, add error handling.
Fix timestamp loop, add error handling.