Fixed texture assertion, some refactoring