fixed ordering issues, compiler was moving some code out of order