I got the issue resolved by combining a function I found elsewhere on the internet with the one I was using. Finally! Thank you all for your support.