Refactor to use with other functions