Moved non main functions to utils. Working version.