converting to better pattern matching, experiencing crash