Add logging and some small changes