Refactor for functions