linux bugfix: using MIN(a,b) instead of windows specific min(a,b)