split waitResult() into it's own function to try to reduce code complexity.