monkey-patching and cleanup of general code