Modified to scala