Add API exception class and some debugging