Add checks to prevent exceeding view bounds