Added license text.
Reformatted the code and fixed a potential cause for a NPE