Code Cleanup and better filtering