Refactoring of Docker code so it can easily be merged in docker mainstream