new code - direct transposition of erlang