fixed issue 1340, bugs in as_dict, thanks Alan