Major refactorying of the module. APIs not affected.