refactored and added implementation detail