Made the code more readable and added documentation.