separating out server code and improving arg handling