Code cleanup, optimization etc

I also moved muc invite to events area.