Extracted normalize(), calculate_xy()