performed slight refactoring