Refactor util functions