Added logging and comments