Several Bug Fixes

State logic reworked.