Ported module code from the original project