veryyyy close to complete. Only minor details left. See todo comments in next commit.