added a proper logger and fixed some bugs