hull function refactoring