Fixed all the errors I had with the original version