Rewritten almost everything + refactored