Move logic from constructor to code block