Fixed distance function and cleaned up directory