Lots of improvements, also added email logging