code refactoring. To be continued