Refactored code and added how-to

Refactored code.