Code Refactoring code from the tutorial from newthinktank