update code to make it working with scala