Fix fatal error processing bugs and add tests