fix some errors occuring when something is nil

Signed-off-by: Moritz Ulrich <ulrich.moritz@googlemail.com>