Improvements to trait handling

This PR contains improvements discussed on issue #43.