modified scala code