Added a simple class module and remove some duplicated code.
Extract all the context logic to an individual module.