Massive refactoring
Solved all memory issues