fixed bugs and added more api logging