Switched to a Fragment way of doing things, and split up code that I did not write into separate classes.

Also added BSD License.