merging duplicate code, and puting things in their right places.