moved get last tag to a function