Fixed a bug in checking joint limits