completed code and comments