Implements beforeFilter functionality