How could I improve this code? - Theo's Typesafe Cult