Reorganized code a tad