Changes of directory implemented to make it more general