Refactor for function chaining