Complete Refactoring

Completely refactored the source code