Group common code into functions for higher maintainability and reduced binary size.
More code refactoring, reducing the binary size a few bytes more.