moved pattern matching to construct