Made more changes so SQL would work. Still need to do more tests, but it's getting late...