Add assert and enhance type safety