Considerable refactoring