Robust error code checking and return value
Factor out update_btime