finished smart code