works fine but has problems with lastPoint