make debug output optional and set return code