major refactoring to finally get rid of Nullpointer