refactored serve script, making it harder to read for no good reason