major cleanup and removal of redundancy