Third try, with Michael's help. Works.
Updates. Added AFR styling, other style tweaks.
Updates after talking to Michael. Now works. Also added in AFR style tweaks.