class refactored to be more generic