added some comments and simplified method