fixes, optimizations
merging some changes