added logging and comments