Moved the factory method to the Scala side.