code from " Learn You Some Erlang for Great Good! "