fixed occasional "invalid argument" error

fixes #46