EDIT: After looking at the responses, the code basically just had some copy-paste coding errors that were giving the result. I've left the original contents in-tact for people interested below, but after fixing the issues and shifting things around I…