Module refactoring

Time to merge it to master