Starting complete re-write for code cleanliness.