code cleaned, more comments and some minor fixes