added length

rewritten parts of code to kotlin
models should be in kotlin