Removed useless code and added some useful comments for each function