fix rebuild command, add new helper function