Added speed optimizations (from decompiled assembly - lost the later versions of the code)