added a lot of logging functionality