Code improvements

Add some more tests, make some code parts work better and implement the StatesUtility::getStateIdForKey method