fixed getLastId bug, cleanup