important fixes from old merge-accounts branch