Fixes State pattern and code clean-up