modified lucian's code