Re-factored code. Runs more efficiently.