refactored the code so that it's more extensible