not done with big math library and added distance parameter