fixed 'invalid argument' resulting in system_error exception