corrected parameter checking in countMessages and getMessages