added EntityException and some fixes