Foundations of session types and behavioural contracts