translation from www.stanford.edu/~ouster/cgi-bin/cs142-winter14