General Refactoring of code.

*License Header added.