Fixed condition and added a more descriptive error message