fixing a couple bugs and add more logging and metrics