Removed unused functions and added more comments.