Modified to be able to use this is a module as well as a script