Updated with integrated collision code.