Restructure code #2

- Remove unnecessary (unused) AMD and global module patterns.
- Splits functionality into several files.
- Improve example and test.