Cleaned code by moving methods to Unit, more states.