code cleaned and comments added