-Copied Chakra 7's algorithm