more robust handling of custom attributes, added log messages, minor cleanups.