Implemented collision check function