close messages button call moved to function