Fix performance bug when sliding along bottom/right walls

The only new commit is eec6e08. The rest is just merging with master and fixing conflicts.