added logging and bug fixes