Added more debugging statements
Wrap all exceptions and return -1 instead