fix bug with write_credentials