Updated stupid algorithm