Refactored some kludges and added more.