fix stupid bug
some performance improvements
some cleanup