added x button on message, also refactored code