added debug mode to print stack trace