Updated to follow rules and recommendations

Included more local variables and increased number of lines to make code more readable.