Move code to a module so I can test it & fix syntax error introduced by b2b62491f4645d024306061541133c5d9e818d0a