Fixed boundaries check (added proper int cast).