Fix constant references, refactor