cleanup and refactoring - stage6