Fix bug where spec type metadata are sometimes added to wrong position

This fixes #77.