fixed some error handling issues