Bug with int16_t overflow in graph function, fix sign issues in median API.