Fixed snags from the Scala port
More to Scala