making sure the delegate methods are called at the appropriate times