Code refactored to add namespaces and use singleton.

Added namespace.
Adapted the code to  PSR-1.
Added singleton to avoid global use.