https://gist.github.com/cvvergara/6246202
I modified 3 functions so that they would work with schemas