more cleanup; fix single-byte encodings; move Random