Added debugging msgs, optimizing for big n