Refactoring.

Refactoring code into methods. Removed some commented code.