added texture function, bug fix, optimize