Added error handling. Misc finishing touches