Got rid of divide by 0 error. Made a few minor optimazations