Refactor function out to helper.ml