State Machine is cleared up

A simple state machine is added to handle the transitions between
different views.