Port over Hashim/Gulzar's changes from the application-specialization branch on google code.