Completed refactoring - stable version