Add gmail support and fix a couple bugs