Epi: deallocate memory on error, properly.
Epi: ooops, add missing header file.