Major refactor. Pretty unstable right now.