first fixed bug
write r function to replay c