Made the code nicer and more efficient.