Simplified code quite a bit.