fixes various bugs revealed by integration tests on custom fields