completed auto code, cleaned