Update Public.php

Only do the class check once, not every time the hook is invoked.