cleaning up main and adding generic factory methods