more efficiency optimizations

Also 2 minor bug fixes