cleanup and refactoring - stage3