Refactoring and added tests for Privmsg