Refactored classes to make it more generalised.