Refactor functions to clip utils

Fixes #42