Optimize some leagacy code.