Refactor declare functions into context methods