Refactor module

This pull request essentially refactors the entire module to solve most of the issues and problems experienced with the older version.