added pesudo code