More tests, secured SQL, reorganize/refactor some helpers