Refactoring a little bit to make this module more flexible. Fixing notice errors