added overlap checks, not debugged