tweaked speed, removed a few debug statements