Scala support
Fix bugs