add ability to get errors and pass optional debug flag