Made the kotlin code a bit more readable and added documentation.