fixed conditional class-switching logic