debugged and fixed