Fixing maximum function