Improves debug mode detection and fixes issues when running the server locally