Big dump of ugly patching code