added comments, check for negative n