added new states and error handling