code refactoring: removed duplicate code