Added a very basic algorithm for handling overlaps