added exception handilng for handling invalid messages