added scala syntax. reorganized