Refactor sql apps