Finally fixed marker selection algorithem