But now! This is the final version! Tested and returns the correct results.