Php code refactored. Util file created to hold helper functions