Cleanup code. Add proper comments