separated out functions for listening for requests and servicing them,
in preparation for making this program multi-threaded.