Refactor some texture manager code. Handle error more nicely.