fix negative argument error (issue #338, #315)