Working on refactoring the code.
Further refactored things to run with an automaticly invoked function