Added a custom substring function