updated algw and added more testcases for applyToExp