minors
improve get last sql
minor fix
improve performance