updated retrieval functionality to work with state masks