code refactored for readability reasons