updated with slightly more complex typing rules