added some pseudo code