Had to modify the code a bit. Some parts started to get messy so had to modify and now the code looks better and it is easier to understand.