fixed #38, added comments, small refactoring for prevPosition keeping
fixed #39