Cleaned up the code somewhat.