Cleanup and better detection