cleaned up some unneeded casts, put all the  manipulation in one syncronized operation instead of three , in an attempt to increase performance