polished code and comments