Fixed mipmaping code, improved and optimized code