updated the code with new comments, rewrote some bad sections