added flushing function
more minor changes (in use outside)