refactored the code to allow a more flexible configuration