reorganize code for closed ticket #155