Updated for vertical and horizontal scrolling