Added idealWeight function