Some code cleanup, removed not used parts and a bit o refactoring