This is so much cleaner than the Java :).
Original source downloaded from Vintage Basic
Conversion to Kotlin