error handling updates, fixed a small bug