convert some code to Kotlin, debug #56