I don't know if this is correct, but unfortunately I have no way of testing it without having access to the AppDB. Is there a way to test this? If I understand the code, and I probably don't, this should be enough.