#677 code refactoring