Refactored some functionalities to separate methods.
Removed some redundant code.
Removed some redundant code and performed other house keeping.