added logic for y-axis scaling