fix bug #271
fixed bug #238
Improved error message for #158