Cleanup and fix empty check