Updated header file and added more comments in, refactored some functions