added flush function