Complete huge refactoring. Close #6