Updated code with custom messages