Refactored code to make it possible for future extension.