Refactored into a module. Also created test cases for functions inside the module