Refactor component code to make more extensible and organized