a newer version using type safe