simplify scala implementation