Added more code to handle overlap case