merging with ali's code