Added exception handling for n<0