Merged with Hung's code for Dep & Xem