Add diagnostic function, fix mastery handling