Splits run function into server/client/local

Introduces some code duplication, but should be cleaned up when
rendering code is moved to own file.