don't calculate when K11 = 0

also some code refactor