move logging to more proper place