Added logging and fixed test