- refactored to allow context to be passed in externally