give error if ranges not defined
fix error handling