Typecasting fixes and more

Made xdist and ydist directional. I wish Javascript would admit it had
data types.