Slightly optimized the MLP code