added checking some return values