Removing redundant functions and adding more comments