fix many things, refactoring needed