refactored and shortened