diff --git a/generate_schema_config.py b/generate_schema_config.py
index 32f4165bbca2db27776f38b2c1aebb78f5ff8c0b..3c2a6b301f08a35df51183e3567506450b644068 100644
--- a/generate_schema_config.py
+++ b/generate_schema_config.py
@@ -112,17 +112,39 @@ swagger_config = {
 
 
 def configure_flask(swagger_config):
+    """
+    Setup a flask app, load flasgger 
+
+    and then patch to remove invalid 
+    definitions:{} object
+    """
     app = Flask(__name__)
     Swagger(app, config=swagger_config, merge=True)
 
+    # Replace schema route to remove invalid
+    # definitions: {}
+    # Should be fixed if Flassger 0.9.7 is released
+    #
+    # The last release of flasgger was Aug 2020
+    # This bug was fixed in Nov 2021
+    # There is a pre-release from May 2023
+    # Until the fix gets released we have to
+    # remove the invalid definitions object
+    # from the spec
     @app.after_request
     def after_request_decorator(response):
-        if type(response).__name__ == "Response":
-            if response.content_type == "application/json":
-                data = response.json
-                if "definitions" in data:
-                    del data["definitions"]
-                response.data = json.dumps(data)
+        """
+        I didn't want to mess with flasgger so 
+        this blunt workaround that runs on every 
+        route and then checks whether it's required
+        """
+        is_response = type(response).__name__ == "Response"
+        is_json = is_response and response.content_type == "application/json"
+        if is_json:
+            parsed = response.json
+            if "definitions" in parsed:
+                del parsed["definitions"]
+            response.data = json.dumps(parsed)
 
         return response
 
@@ -131,18 +153,8 @@ def configure_flask(swagger_config):
 
 def serve(swagger_config):
     """
-    Run as local flask app on port 5000
+    Run as local flask app on FLASK_PORT|5000
     """
-    # Replace schema route to remove invalid
-    # definitions: {}
-    # Should be fixed if Flassger 0.9.7 is released
-    #
-    # The last release of flasgger was Aug 2020
-    # This bug was fixed in Nov 2021
-    # There is a pre-release from May 2023
-    # Until the fix gets released we have to
-    # remove the invalid definitions object
-    # from the spec
     app = configure_flask(swagger_config)
     app.run(debug=True, host=FLASK_HOST, port=FLASK_PORT)