code clean up and structure changes