reduced code duplication. Implemented Feature request 1412