Added more advanced scroll detection logic
Changed to use tighter scoping when adding/removing classes