Encapsulated repeated code

removed unnecesary comparisons
removed collision hack
removed unnused variables