Reformulated i_w and removed dublicate declaration of medium.