Added time functionality and some error handling