Remove unchecked/unsafe operations in Scala code