Refactored secondary structure functions