I haven't checked the code carefully but it seems that you never assigned to LastPos and LastP after this [commit](https://github.com/adryzz/CustomFilter/commit/cb66011c0cfb67471ffbe0bb3b970234e7b332fa#diff-6a03090f72d68abbfa664e9354a98da3cb78f5c6538cf858a89b075f0525838fL68)