Restructure and generalize for generic plugin architecture