Refactoring and adding some texture code