Some refactoring to clean up code and to fix an issue with vs theme