Code Refactoring

- Miscellaneous code refactoring and updates