restructure of code and removal of redundant code