Figuring it out

Inserted functions to make the code better.