Changed around some of the stuff I borrowed from mail-listener