Refactoring and cleaning the code.

Made the example more functional.