added a nicer interface and fixes some debug bugs