Cleaned up and documented.