Fixing bugs with avoiding rect() in box