Fix accounting SQL statements and misc fixups