change to scala native implementation