port samples to scala code