refactoring: extract some methods for easier reading