Refactor to avoid dependency issues