Refectored pattern a bit.