fixed bugs and added logging info