Simplified if nesting, added break statement, flattened hits array.