Refactor handle_collisions function from void to int