@rhattersley's suggested review (partial).
Latest incarnation.