logging and some bug fixes