Util

- Added includes to make FreeBSD happy.
- Added more error handling.