Refactor: split out request handling from Main