pseudo-code format adjusted