Move helper function down