Using code from Pragprog Erlang 2nd Edition