add a private class and move code as much as possible