added some comments and fixed selection box bug