Added state manager and changed keyboard handling