Added collision detection code

Not sure if it works...