refactoring code resolves #495