removed the old function and replaced with new code