Refactoring

I tested what I could but since I don't have all the data I couldn't test everything. You need to make sure things are still working..