Major refactor with a much cleaner interface.