#356 Code refactoring