optimizing fav code