Refactored a little
Finished attempting to fix the sql in tags