Added block movement. Improved loop detection algorithm.