refactor core functions