Simplified code and fixed collisions.