almost finished pseudo code