Advanced immunity system. Fixes #896