Cleaned up the code: the limit checking and clipping to limits has been imlemented.