Improved entity processing.
Exception handling added.