change schema and refactor code