Updated Function to use more templates and be compatible with new lib version.
Updated library to fix bug.
Updated optimizers to use more templates and be compatible with new lib version.