refactor out core

adds core tests among other things.