code refactoring and changes to code layout