Trying to translate this project to scala implementation.(also helps reviewing code)