added some quasi-psuedo code, feel free to change any of it