refactor to only take the last id, cleanup of debugging