fixed bug in calculating switch status

+ cleanup