Adding functions for optimization