refactor to scala style