Added preInit and postInit and cleaned up some code