Finished a version of the scala code