fixed copy&paste error; some minor optimizations