Function written. Working on debugging
Fixed merge conflicts