Start of encounter code.