Solves problem with empty nodes causing nan