added a logger and fixed bug