small fixes and optimization