rewrite the back end processing for increased efficiency. Front end unchanged