Extract code from server-im and adjust for new architecture sans polyglot