Made the code more readable, removed unnecessary methods and rewrote some comments.