modified shu's code