some optimizations in position.cpp