Improve error handling, add variable for timing