Code and parameters explained. Code indented and optimized