Refactor core functions in to separate file