code cleaning
Restructured some functions + updated the mocha test function