finished kotlin conversion