added code and pseudo code