fix for issue #221; still needs some enhancements though