Refactor util functions into util namespace