Changes needed for optional AMD loading

This is the other portion separated from my first pull request. Please note that I did not indent the code properly as of yet, because I think that is what caused the diff to get messed up on my last pull request (every line had 'changed').

So if  you decide to accept this pull request, there should be one more commit to properly indent the code.