Adding documentation and optimizing code