Improve 'simplify' function