Improved sliding logic