refactor functions out of init