Cleanup, add comments, test the error calculation