Finally got it working. Strange lines of code