Moved common code to utils package.
Moved more common code to utils. Refactored.