Developed a function that makes the magic happend