This should fix issue #4

You weren't storing the lastX, lastY and lastZ values.
Merge pull request #5 from peterhry/patch-1

This should fix issue #4