Updated terrible, terrible code from when I was first learning JavaScript