added mail checking, minor refactor