Refactored class to make it more generic