Made modifications to the check_unackd messages script for performance