add cast; refactoring erlang modules