added some pseudo-code