added logging and fixed errors