Cleaned up and commented a bit.