Fixed logic in new message scan; found new bugs