Refactored the sql module.