refactored to reduce length of code