Code refactored.
Messages functionality done.