Migrate some code to Kotlin