Fix max amount function