refactored & reduced code