Split app to client and server methods

Also add infinite while loops