Add bounds checking to focus function.

Change-Id: I68b9366126a348be51ffcd23d158e5e6aa18bd65