Added some logging and comments