Modified script to filter messages in a better manner.