refactoring of the gateway model in the client. also cleanup/whitespace