added the two necessary checks. thanks for pointing this out.