minor optimizations, fixes bug