Based on Scala&Python