Fixed the object tracking and made it more robust