This structure is very difficult to follow. Please replace with if statements explaining what the logic is doing.