Converting some pseudocode, not completed..