Updated normal calculation code for better accuracy