Performed some re-factoring to make code more readable.