logging and some improvements