final version of the sql portion, woo.