Refactor error module to be a singleton