improved structure, continued startup code and fixed some bugs