Started refactoring in php.