Fixes #3 negative value for cost or reverse cost crashes server.