Added full example code and refactored slightly, added attributions