fixed some bugs and added more log messages