some error checking and bug fixes, properly searching for invalid trailers, too