Cost-Directed Refactoring for Parallel Erlang Programs