Alot of small fixes. Add support for the 'type' field.