Fixing twisted bones on avatars

Sometimes after import avatar’s bones appear horribly twisted:

To fix this, first go to armature properties and enable displaying bone axes:
Then check orientations on default armature:
Select your armature, go to edit mode and reorient the bones, so that they are oriented in the same way as in in default armature. To change bone orientation select bone, and then go to Armature->Bone Roll->Recalculate Bone Roll->Global ... Axis and then export the model again. Make sure to do Edit->Reload content in game, because otherwise old version will be cached.