This was damned difficult to get right!