ejabberd is an open source, scalable, extendible, cross-platform Jabber/XMPP server written in Erlang. During the last few years we have been involved in building and optimizing a number of projects integrating ejabberd server with various subsystems; starting from regular IMs, going through social networks, banking, online gaming and finishing with mobile applications. Basing on that experience we introduced a set of refactorings applied to ejabberd sources, as well as code optimizations, giving the machines hosting ejabberd significant RAM savings. I will also describe escalus framework, which can be used for blackbox testing of XMPP servers. At ESL we developed test suites based on it, which covers some Jabber RFCs and can be used for regression testing when XMPP server is being refactored.