diff --git a/CHANGES.md b/CHANGES.md
index 5f00f0ee..f0b6366a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -547,6 +547,10 @@
     - Added `defWPNamesJpg` as an alias to `defWPNames` and deprecated
       the latter.
 
+  * `XMonad.Layout.SubLayouts`
+
+    - Floating windows are no longer moved to the end of the window stack.
+
 ## 0.16
 
 ### Breaking Changes
diff --git a/XMonad/Layout/SubLayouts.hs b/XMonad/Layout/SubLayouts.hs
index 01655183..60b9c7ba 100644
--- a/XMonad/Layout/SubLayouts.hs
+++ b/XMonad/Layout/SubLayouts.hs
@@ -62,6 +62,7 @@ import qualified XMonad.Layout.BoringWindows as B
 import qualified XMonad.StackSet as W
 import qualified Data.Map as M
 import Data.Map(Map)
+import qualified Data.Set as S
 
 -- $screenshots
 --
@@ -442,9 +443,13 @@ updateWs = windowsMaybe . updateWs'
 updateWs' :: Groups Window -> WindowSet -> Maybe WindowSet
 updateWs' gs ws = do
     f <- W.peek ws
-    let w = W.index ws
-        nes = concatMap W.integrate $ mapMaybe (flip M.lookup gs) w
-        ws' = W.focusWindow f $ foldr W.insertUp (foldr W.delete' ws nes) nes
+    let wins = W.index ws
+    let wset = S.fromList wins
+    let gset = S.fromList $ concatMap W.integrate $ M.elems $
+            M.filterWithKey (\k _ -> k `S.member` wset) gs -- M.restrictKeys (ghc 8.2+)
+    st <- W.differentiate . concat $ flip map wins $ \w ->
+        if w `S.member` gset then maybe [] W.integrate (w `M.lookup` gs) else [w]
+    let ws' = W.focusWindow f $ W.modify' (const st) ws
     guard $ W.index ws' /= W.index ws
     return ws'