works. prints out intermediate results, but that's fine.