code cleanup and added turning scaler
merged Daniel's changes, not sure if it runs...
integrated state machine
ran formatter