Added util.php for utility functions.
Some code refactoring done.