cleaning up the code, rename createDocument to getOrCreateDocument and createProxy to getOrCreateProxy