code cleaned w some comments added