added some comments
renamed some function