Fix crashes while adding accounts

Also add some headers and some other fixes as well