cleanup and add more code comment