Need help writing more efficient code (total newbie)