Added error check, fixed some error messages.