add logging and fix some minor issues