Basic outline, still buggy.