Reorganised for better readability in article

Moved "lead" to the front of the code so its more readable, pushing
exception handling and other elements towards the end