Refactor common code. Add basic sql schema.