modified flatten function
add delay function
once function implemented