added bounding box checks and re-ordered params