Refactored code and wrote functions for addr message