Slight refactoring, need to add overlapping detection