Refined code with physics