Refactored and Restructured Code

Refactoring, deleting unused functions etc..