minor bug fix; some (hopeful) optimizations