LQ ported from Scala