optimization of the check_overlap method