added bugs and intersection calculation