code moved to scala