refactoring for second stage