In the process of writing the function code, tested it out once and it did not work properly, rewriting it now, and will test again.