Add comments and remove unnecessary functions for making codes clear.