decimation key error

Strange error with the decimation key fixed by moving write_key into
the function