Fixed problem with wrap_json mixing up order of arguments.
Added support for classes with db.key other than 'id'.