refactor to static functions so we can re-use it.