Change code structure for more flexibility