add more efficient erlang solution