Documented the functions used and cleaned up unused variables