moved schema writing code