positioning rests when swtiching states, code cleanup