debugged and commented a little