optimized some - these might actually have a lot of the same changes as the first pull request i made sorry