Fixed some bugs from the original.