cleanup and refactoring - stage5