Some Scala code shared for reuse