midpoint algorithm is working