Adding documentation, cleaning code