flush code and some logging