Move some nested call to functions & documentation
Removes unused code, simplifies function call