moved the check collisions logic out into a separate function