updated to more closely resemble the Scala version