major improvements to first iteration