added logging and minor bug fixes