Added some more detection and removed reliance on 'active' css class