Refactored slightly, although binding 'fn' is probably frowned on