Fixed chat bug plus some code cleaning up.