Refactored Code. Added Message Functions.