Cleaned up error checks