Retrieve docs

Closes #3 

Hey @devcritter if you are able to, a review would be good.
I know this is borrowed code, but this looks very difficult to maintain to me - it's doing a lot of work. Maybe it'd be nice to refactor this? I guess it might be a lot of work though, so it's okay if you don't look it into now, I just wanted to mention it.