Cleaned up, and made most things functions