Basic algorithm to find shortest distance - to be improved on.