State logic does not seem to be working