refactored for better understandability