UINT -> UINT8 for oldPos/newPos, they're being cast later anyway.
Style consistency.
Simplify condition.
Free unused memory blocks.
Merge pull request #3 from RaMMicHaeL/pr2

A couple of other improvements