adding logging and fixing a few bugs