added new code (untested).