Reordered code a little bit. Now trying to speed some stuff up.