Need help converting and optimizing