cleaned up code and changes variable names (sorry jem. trr, tr1, tr1 @_@)