added more comments and code