Some refactoring and started adding server support for API key