updated with working flush functionality