#848 code refactoring