added more comments, added a commit safety, and generalized the script