Fix silent exit and wrong error code