udpated and tested