Massive refactor. Working towards separating the preview.