first version of working scala code