added error logging, haven't tested it