Refactored code to use the statemachine gem, which makes invalid transitions impossble and makes the code easier to maintain.