Cleaned up the main code.