Refactor, move stuff around, clean up API