Cleaned up the code in  a bit.