Fixing gradle errors and refactoring