Structure

This adds structure by wrapping the entire library in an anonymous function and the necessary functions etc into one namespace. It also removes trying to copy the iOS API exactly (which proved to be a bad idea). This should help make the library easier to extend and maintain.