State machine implemented needs tweaking.