add various improvements to code