I simplified it (no more crazy variables ;) ) and also fixed the bug.
Minimum size for the sprite is 26, BTW