Clean up file and add ids to Advanced fields
Refactor function order and cleanup comments