Optimise classList usage and reduce if statement