bug fixes + various reductions in code