cleaned up code and unified the implementation of states