textures

Got textures working, did some refactoring and made some performance
improvements.