Fixed bugs and improved collision handling.