Refactor: remove dead code and replace local fields with method calls