refactor value retrieval into a single function