Combined all the functions

I had to change a few things with Davids functions to make it work.