refactored code of bug #198