update error handling to print to stderr; update tests