added comments
added some comments + refactoring and sorting. some bug fixes