some modification on retrieve function