Edited to be able to be used as a module which can be imported for use