Streamlined spatial transform code
Fixed some bugs