Refactored commonly used code.