improved trait parsing code