Fixing a bug in horizontal and vertical resizing