refactored and removed unnecessary duplications