Huge commit, implement rough working version of the whole resolve process.