Fix ticket creation and code cleanup