Corrected some bad arithmetic and wrote more succinct tests. Started adding JSDocs.