Improved zoomToFit function