Code from CMPS 12A/L W14 at UCSC