fixed conditional checking for Ak == 0