Un-fixed the 'bug' in terms of how A and p are connected; it was correct the first time.