Big commit, sorry. First working draft.