Lots of fixing & cleanup

I changed quite some things to make the cookbook more solid, and work better in more cases (like HA deployment). Apologies for the big PR...