Added more error handlers and added comments