improved the code in the latest commit. Using the above looks appropriate, thanks @colemanw