Correct scalar product function