Collisions with walls. Some refactoring