minor fixes and optimization